home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Games / Hexagonal CA / HexCA.c / CoreDialogUtil.c next >
Encoding:
C/C++ Source or Header  |  1997-05-25  |  4.3 KB  |  175 lines  |  [TEXT/CWIE]

  1. #include "AppMacros.h"
  2. #include "ToolTrapsPr.h"
  3.  
  4. #include "CoreDialogUtilPr.h"
  5.  
  6. /* DLOGStandardProc -        uses button 1 as default, button 2 as cancel
  7.                             processes Return, Enter and cmd .
  8. */
  9. pascal Boolean DLOGStandardProc( DialogRef theDialog, EventRecord *theEvent, short *theItem )
  10. {
  11.     short            type;
  12.     Rect            box;
  13.     char            c;
  14.     long            endTicks;
  15.     Boolean            result;
  16.     Handle            item;
  17.     
  18.     c = (theEvent->message & charCodeMask);
  19.     
  20.     if (c == 13 || c == 3)        /* return or enter */
  21.     {        
  22.         GetDItem (theDialog, 1, &type, &item, &box);
  23.         
  24.         HiliteControl ((ControlHandle)item, true);
  25.         Delay (8, &endTicks);
  26.         HiliteControl ((ControlHandle)item, false);
  27.         
  28.         *theItem = 1;
  29.         theEvent->what = mouseDown;
  30.         result = true;
  31.     }
  32.     else if ((c == '.' && theEvent->modifiers & cmdKey) || (c == 0x1B))    /* cmd . */
  33.     {        
  34.         GetDItem (theDialog, 2, &type, &item, &box);
  35.         
  36.         HiliteControl ((ControlHandle)item, true);
  37.         Delay (8, &endTicks);
  38.         HiliteControl ((ControlHandle)item, false);
  39.         
  40.         *theItem = 2;
  41.         theEvent->what = mouseDown;
  42.  
  43.         result = true;
  44.     }
  45.     else
  46.         result = false;
  47.     
  48.     return (result);
  49. }
  50.  
  51. // GetItemHandle -    returns the given item's control handle
  52. ControlHandle GetItemHandle( DialogRef theDlog, short theItem )
  53. {
  54.     short        itemType = 0;
  55.     Rect        itemRect = { 0, 0, 0, 0 };
  56.     Handle        cntHdl = nil;
  57.     
  58.     GetDialogItem( theDlog, theItem, &itemType, &cntHdl, &itemRect);
  59.     return( (ControlHandle)cntHdl );
  60. }
  61.  
  62. // SetItemHandle -    sets the control handle according to some pre-defined constants (in "DialogUtilPr.h")
  63. void SetItemHandle( DialogRef theDlog, short theItem, short theCnt )
  64. {
  65.     short        itemType = 0;
  66.     Rect        itemRect = { 0, 0, 0, 0 };
  67.     Handle        cntHdl = nil;
  68.     
  69.     GetDialogItem( theDlog, theItem, &itemType, &cntHdl, &itemRect);
  70.     switch( theCnt )
  71.     {
  72.         case pBWButtonOutlineProc:
  73.             SetDItem( theDlog, theItem, itemType, (Handle)NewUserItemProc(indentBWButtonProc), &itemRect );
  74.             break;
  75.     }
  76. }
  77.  
  78. // ItemVisible -    returns whether the given item is visible or not
  79. Boolean ItemVisible( DialogRef theDlog, short theItem )
  80. {
  81.     return( (**GetItemHandle( theDlog, theItem )).contrlVis == 255 );
  82. }
  83.  
  84. // GetItemValue -    returns the given item's control value
  85. short GetItemValue( DialogRef theDlog, short theItem )
  86. {
  87.     return( GetControlValue( GetItemHandle( theDlog, theItem ) ) );
  88. }
  89.  
  90. // SetItemValue -    sets the given item's control value
  91. void SetItemValue( DialogRef theDlog, short theItem, short theValue )
  92. {
  93.     SetControlValue( GetItemHandle( theDlog, theItem ), theValue );
  94. }
  95.  
  96. // InvertItem -    if a button is on, it is made off, and vica verca
  97. void InvertItem( DialogRef theDlog, short theItem )
  98. {
  99.     ControlHandle    cntHdl = nil;
  100.     
  101.     cntHdl = GetItemHandle( theDlog, theItem );
  102.  
  103.     if( cntHdl )
  104.         SetControlValue( cntHdl, !( GetControlValue( cntHdl ) ) );
  105. }
  106.  
  107. // SetTextValue -    sets the text box to the number given
  108. void SetTextValue( DialogRef theDlog, short theItem, long theValue )
  109. {
  110.     Str255        theString;
  111.     
  112.     NumToString( theValue, theString );
  113.     SetIText( (Handle)GetItemHandle( theDlog, theItem ), theString );
  114. }
  115.  
  116. // GetTextValue -    returns the number in the given text box
  117. long GetTextValue( DialogRef theDlog, short theItem )
  118. {
  119.     Str255        theString;
  120.     long        theValue = 0;
  121.     
  122.     GetIText( (Handle)GetItemHandle( theDlog, theItem ), theString );
  123.     StringToNum( theString, &theValue );
  124.     
  125.     return( theValue );
  126. }
  127.  
  128. // EnableDisableItem -    enables or disables the dialog item
  129. void EnableDisableItem( DialogRef theDlog, short theItem, Boolean enable )
  130. {
  131.     ControlHandle        cntHdl = nil;
  132.     short            value = 0;
  133.     
  134.     if( enable )
  135.         value = 0;
  136.     else
  137.         value = 255;
  138.         
  139.     cntHdl = GetItemHandle( theDlog, theItem );
  140.     
  141.     if( (**cntHdl).contrlHilite != value )
  142.         HiliteControl( cntHdl, value );
  143. }
  144.  
  145. // GetItemRect -    gets the rectangle of the given control
  146. void GetItemRect( DialogRef theDlog, short theItem, Rect *theRect )
  147. {
  148.     short        itemType = 0;
  149.     Handle        cntHdl = nil;
  150.     
  151.     GetDialogItem( theDlog, theItem, &itemType, &cntHdl, theRect );
  152. }
  153.  
  154. // indentBWButtonProc -    draw a B&W outline round the button
  155. pascal void indentBWButtonProc( DialogRef theDialog, short theItem )
  156. {
  157.     short            type;
  158.     Rect                box;
  159.     Handle            itemHdl = nil;
  160.     GrafPtr            savePort = nil;
  161.         
  162.     GetPort( &savePort );
  163.     SetPort( theDialog );
  164.     
  165.     ForeColor( blackColor );
  166.     
  167.     GetDItem( theDialog, theItem, &type, &itemHdl, &box );
  168.     
  169.     PenSize( 3, 3 );
  170.     MInsetRect( box, -4, -4 );
  171.     FrameRoundRect( &box, 16, 16 );
  172.     PenNormal();
  173.     
  174.     SetPort( savePort );
  175. }